
#include "TextureDao.h"


TextureDao::TextureDao(void) {
	this->db = DB::getInstance();
}	

TextureDao::~TextureDao(void){

}

void TextureDao::save(Element * object){
	try {
		if(object->getId().empty()) {
			object->setId(this->db->getSequenceID());
		}
		this->find(object->getId());
		throw PersistenceUniqueConstraintException("Se intento guardar un elemento duplicado.");
	}catch(NoSuchElementException e) {
		this->db->getTextures()->insert(make_pair(object->getId(),object));
	}	
}

Element * TextureDao::find(string id){
	map<string,Element *>::iterator iter = db->getTextures()->find(id);
	if(iter != db->getTextures()->end()) {
		return iter->second;
	}
	throw NoSuchElementException("No existe el elemento con ese id");
}

list<Element *> * TextureDao::findAll(void){
	list<Element *> * result = new list<Element *>();
	map<string,Element *>::iterator iter;
	for(iter = this->db->getTextures()->begin() ; iter != this->db->getTextures()->end() ; ++iter) {
		result->push_front(iter->second);
	}
	return result;
}

void TextureDao::deleteObject(Element * objectToDelete){

}

